import { IdBO, IdsBO } from "@/constant/types"
import { RequestConfigExtra, usePost } from "@/http"

const queryOptions: RequestConfigExtra = {
    success: false,
    error: true
}

const options: RequestConfigExtra = {
    success: true,
    error: true
}

const search = async (params: any) => {
    return usePost("/system/user/search", params ?? {}, queryOptions)
}

const disable = async (params: IdsBO) => {
    return usePost("/system/user/disable", params ?? {}, options)
}

const enable = async (params: IdsBO) => {
    return usePost("/system/user/enable", params ?? {}, options)
}

const deleteBatch = async (params: IdsBO) => {
    return usePost("/system/user/delete", params ?? {}, options)
}

const add = async (params: Recordable) => {
    return usePost("/system/user/add", params ?? {}, options)
}

const update = async (params: Recordable) => {
    return usePost("/system/user/update", params ?? {}, options)
}

/**
 * 查询指定用户的所有角色ID
 */
const roleIds = async (params: IdBO) => {
    return usePost("/system/user/roleIds", params ?? {}, queryOptions)
}

/**
 * 查询所有角色
 */
const roleSelector = async () => {
    return usePost("/system/role/selector", {}, queryOptions)
}

export const api = { search, disable, enable, delete: deleteBatch, add, update, roleIds, roleSelector }
